package biz.bbtec.sbm.store.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import biz.bbtec.sbm.store.bean.AddressBean;
import biz.bbtec.sbm.store.factory.AddressFactory;
import biz.bbtec.sbm.store.service.AddressService;
import biz.bbtec.sbm.user.bean.UserBean;

public class AddressAction extends ActionSupport {

	private AddressBean add = new AddressBean();
	private Map session;
	private List<AddressBean> addlist = new ArrayList<AddressBean>();

	public List<AddressBean> getAddlist() {
		return addlist;
	}

	public void setAddlist(List<AddressBean> addlist) {
		this.addlist = addlist;
	}

	public Map getSession() {
		return session;
	}

	public void setSession(Map session) {
		this.session = session;
	}

	public AddressBean getAdd() {
		return add;
	}

	public void setAdd(AddressBean add) {
		this.add = add;
	}

	public String AddAddress() {

		Map session = ActionContext.getContext().getSession();
		UserBean user = (UserBean) session.get("user");
		add.setOrgid(user.getOrgid());
		AddressService addservice = AddressFactory.getInstance()
				.creattemService();
		if (!(addservice.AddAddress(add))) {
			this.addActionError("添加失败！");
			return INPUT;
		}
		return SUCCESS;
	}

	public String ShowAllAddress() {
		Map session = ActionContext.getContext().getSession();
		UserBean user = (UserBean) session.get("user");
		AddressService addservice = AddressFactory.getInstance()
				.creattemService();
		addlist = addservice.showalladdress(user);
		if (addlist.size() == 0) {
			this.addActionMessage("请您添加新的仓库地址！");
			return INPUT;
		}
		return INPUT;
	}
}
